//
//  BaseViewController.m
//  MyFunctionDemo
//
//  Created by Ting Han on 2017/9/21.
//  Copyright © 2017年 Ting Han. All rights reserved.
//

#import "BaseViewController.h"


@interface BaseViewController ()<UIGestureRecognizerDelegate>
@property (nonatomic,strong) NSMutableDictionary <NSString *,BaseViewControllerConfig*> *viewsConfig;
@end

@implementation BaseViewController

NSString * const titleViewId       = @"titleViewId";
NSString * const loadingAreaViewId = @"loadingAreaViewId";
NSString * const windowAreaViewId  = @"windowAreaViewId";
NSString * const contentViewId     = @"contentViewId";
NSString * const backgroundViewId  = @"backgroundViewId";

- (void)viewDidLoad {
    [super viewDidLoad];
    self.automaticallyAdjustsScrollViewInsets = NO;
    //加载数据
    [self setupDataSource];
    //初始化config
    [self initViewsConfigs];
    //子类修改config
    [self makeViewsConfig:self.viewsConfig];
    //加载config对应的Views
    [self buildConfigViews];
    //子类加载子View
    [self setupSubViews];
    
}
- (void)initViewsConfigs {
    
    self.viewsConfig = [[NSMutableDictionary alloc] init];
    CGFloat width    = [UIScreen mainScreen].bounds.size.width;
    CGFloat height   = [UIScreen mainScreen].bounds.size.height;
    // backgroundView config.
    {
        BaseViewControllerConfig *config   = [BaseViewControllerConfig new];
        config.isExist                       = YES;
        config.frame                       = CGRectMake(0, 0, width, height);
        config.backgroundColor             = [UIColor whiteColor];
        self.viewsConfig[backgroundViewId] = config;
    }
    
    // contentView config.
    {
        BaseViewControllerConfig *config = [BaseViewControllerConfig new];
        config.isExist                     = YES;
        config.frame                     = CGRectMake(0, 64, width, height - 64);
        config.backgroundColor           = [UIColor clearColor];
        self.viewsConfig[contentViewId]  = config;
    }
    
    // titleView config.
    {
        BaseViewControllerConfig *config = [BaseViewControllerConfig new];
        config.isExist                     = YES;
        config.frame                     = CGRectMake(0, 0, width, 64.f);
        config.backgroundColor           = [UIColor clearColor];
        self.viewsConfig[titleViewId]    = config;
    }
    
    // loadingAreaView config.
    {
        BaseViewControllerConfig *config    = [BaseViewControllerConfig new];
        config.isExist                        = YES;
        config.frame                        = CGRectMake(0, 64, width, height - 64.f);
        config.backgroundColor              = [UIColor clearColor];
        self.viewsConfig[loadingAreaViewId] = config;
    }
    
    // windowAreaView config.
    {
        BaseViewControllerConfig *config   = [BaseViewControllerConfig new];
        config.isExist                       = YES;
        config.frame                       = CGRectMake(0, 0, width, height);
        config.backgroundColor             = [UIColor clearColor];
        self.viewsConfig[windowAreaViewId] = config;
    }
    
}
- (void)buildConfigViews {
    
    // backgroundView
    {
        BaseViewControllerConfig *config = self.viewsConfig[backgroundViewId];
        if (config && config.isExist) {
            
            UIView *view         = [[UIView alloc] initWithFrame:config.frame];
            view.backgroundColor = config.backgroundColor;
            [self.view addSubview:view];
            self.backgroundView  = view;
        }
    }
    
    // contentView
    {
        BaseViewControllerConfig *config = self.viewsConfig[contentViewId];
        if (config && config.isExist) {
            
            UIView *view         = [[UIView alloc] initWithFrame:config.frame];
            view.backgroundColor = config.backgroundColor;
            [self.view addSubview:view];
            self.contentView     = view;
        }
    }
    
    // titleView
    {
        BaseViewControllerConfig *config = self.viewsConfig[titleViewId];
        if (config && config.isExist) {
            
            UIView *view         = [[UIView alloc] initWithFrame:config.frame];
            view.backgroundColor = config.backgroundColor;
            [self.view addSubview:view];
            self.titleView       = view;
        }
    }
    
    // loadingAreaView
    {
        BaseViewControllerConfig *config = self.viewsConfig[loadingAreaViewId];
        if (config && config.isExist) {
            
            ShowLoadingView *view = [[ShowLoadingView alloc] initWithFrame:config.frame];
            view.backgroundColor  = config.backgroundColor;
            [self.view addSubview:view];
            self.loadingAreaView  = view;
        }
    }
    // windowAreaView
    {
        BaseViewControllerConfig *config = self.viewsConfig[windowAreaViewId];
        if (config && config.isExist) {
            
            ShowLoadingView *view = [[ShowLoadingView alloc] initWithFrame:config.frame];
            view.backgroundColor  = config.backgroundColor;
            [self.view addSubview:view];
            self.windowAreaView   = view;
        }
    }
}

- (void)didReceiveMemoryWarning {
    [super didReceiveMemoryWarning];
    // Dispose of any resources that can be recreated.
}

- (void)makeViewsConfig:(NSMutableDictionary <NSString *, BaseViewControllerConfig *> *)viewsConfig {
    
}

- (void)setupDataSource {
    
}

- (void)setupSubViews {
    
}



#pragma mark --- 手势滑动返回
- (void)useInteractivePopGestureRecognizer{
    self.navigationController.interactivePopGestureRecognizer.delegate = self;
}
@synthesize enableInteractivePopGestureRecognizer = _enableInteractivePopGestureRecognizer;
- (void)setEnableInteractivePopGestureRecognizer:(BOOL)enableInteractivePopGestureRecognizer{
    _enableInteractivePopGestureRecognizer = enableInteractivePopGestureRecognizer;
    self.navigationController.interactivePopGestureRecognizer.enabled = enableInteractivePopGestureRecognizer;
}
- (BOOL)enableInteractivePopGestureRecognizer{
    return _enableInteractivePopGestureRecognizer;
}
#pragma mark --- 状态栏是否隐藏
//局部隐藏
//- (BOOL)prefersStatusBarHidden{
//    return YES;
//}
//全局隐藏
//[UIApplication sharedApplication].statusBarHidden = YES;
//字体颜色
//[UIApplication sharedApplication].statusBarStyle = UIStatusBarStyleLightContent;
//局部字体颜色
//- (UIStatusBarStyle)preferredStatusBarStyle{
//    
//    return UIStatusBarStyleLightContent;
//}
@end
